package com.ruoyi.warehouse.controller;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.warehouse.domain.CkWarehouse;
import com.ruoyi.warehouse.domain.CpkcFnishedProductInventory;
import com.ruoyi.warehouse.domain.CprkProductStorageForm;
import com.ruoyi.warehouse.service.ProductStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 成品入库Controller
 *
 * @author ruoyi
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/cprk")
public class ProductStorageController extends BaseController {
    @Autowired
    private ProductStorageService productStorageService;

    /**
     * 查询产品入库列表
     */
    @RequiresPermissions("warehouse:cprk:list")
    @GetMapping("/list")
    public TableDataInfo list(CprkProductStorageForm cprkProductStorageForm)
    {
        startPage();
        List<CprkProductStorageForm> list = productStorageService.selectCprkProductStorageFormList(cprkProductStorageForm);
        return getDataTable(list);
    }

    /**
     * 导出产品入库列表
     */
    @RequiresPermissions("warehouse:cprk:export")
    @Log(title = "产品入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CprkProductStorageForm cprkProductStorageForm)
    {
        List<CprkProductStorageForm> list = productStorageService.selectCprkProductStorageFormList(cprkProductStorageForm);
        ExcelUtil<CprkProductStorageForm> util = new ExcelUtil<CprkProductStorageForm>(CprkProductStorageForm.class);
        util.exportExcel(response, list, "产品入库数据");
    }

    /**
     * 获取产品入库详细信息
     */
    @RequiresPermissions("warehouse:cprk:query")
    @GetMapping(value = "/{rkCode}")
    public AjaxResult getInfo(@PathVariable("rkCode") String rkCode)
    {
        return success(productStorageService.selectCprkProductStorageFormByRkCode(rkCode));
    }

    /**
     * 新增产品入库
     */
    @RequiresPermissions("warehouse:cprk:add")
    @Log(title = "产品入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CprkProductStorageForm cprkProductStorageForm)
    {
        return toAjax(productStorageService.insertCprkProductStorageForm(cprkProductStorageForm));
    }

    /**
     * 修改产品入库
     */
    @RequiresPermissions("warehouse:cprk:edit")
    @Log(title = "产品入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CprkProductStorageForm cprkProductStorageForm)
    {
        return toAjax(productStorageService.updateCprkProductStorageForm(cprkProductStorageForm));
    }

    /**
     * 删除产品入库
     */
    @RequiresPermissions("warehouse:cprk:remove")
    @Log(title = "产品入库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{rkCodes}")
    public AjaxResult remove(@PathVariable String[] rkCodes)
    {
        return toAjax(productStorageService.deleteCprkProductStorageFormByRkCodes(rkCodes));
    }

    /**
     * 产品信息
     *
     * @param cpkc 产品信息
     * @return 结果
     */
    @GetMapping("/cpList")
    public TableDataInfo ckList(CpkcFnishedProductInventory cpkc)
    {
        startPage();
        List<CprkProductStorageForm> list = productStorageService.selectCp(cpkc);
        return getDataTable(list);
    }

    /**
     * 审核
     *
     * @param rkCode 审核
     * @return 结果
     */
    @RequiresPermissions("warehouse:cprk:examine")
    @PostMapping("/examine/{rkCode}")
    public AjaxResult examine(@PathVariable String rkCode)
    {
        return toAjax(productStorageService.insertCpkcStorage(rkCode));
    }

    /**
     * 撤销
     *
     * @param rkCode 撤销
     * @return 结果
     */
    @RequiresPermissions("warehouse:cprk:cancel")
    @PostMapping("/cancel/{rkCode}")
    public AjaxResult cancel(@PathVariable String rkCode)
    {
        return toAjax(productStorageService.cancelCpkcStorage(rkCode));
    }
}
